package com.tsinghua.server.base.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tsinghua.server.common.Result;
import com.tsinghua.server.base.entity.DataSampleEntity;
import com.tsinghua.server.base.entity.Fxct1914ztwyEntity;
import com.tsinghua.server.base.mapper.DataSampleMapper;
import com.tsinghua.server.base.mapper.Fxct1914ztwyMapper;
import com.tsinghua.server.base.service.DataSampleService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

@Service
public class DataSampleServiceImpl implements DataSampleService {
    @Resource
    DataSampleMapper dataSampleMapper;
    @Resource
    Fxct1914ztwyMapper fxct1914ztwyMapper;

    @Override
    public Result getList(DataSampleEntity dataSampleEntity, Integer pageSize, Integer PageNo) {
        QueryWrapper<DataSampleEntity> wrapper = new QueryWrapper<>();
        wrapper.setEntity(dataSampleEntity);
        Page<DataSampleEntity> page = new Page<>(PageNo, pageSize);
        IPage<DataSampleEntity> iPage = dataSampleMapper.selectPage(page,wrapper);
        for (DataSampleEntity d : iPage.getRecords()) {
            Fxct1914ztwyEntity fxct1914ztwyEntity = fxct1914ztwyMapper.selectByName(d.getFxrZt());
            d.setFxct1914ztwyEntity(fxct1914ztwyEntity);
        }
        Map retMap = new HashMap();
        retMap.put("total", iPage.getTotal());
        retMap.put("data", iPage.getRecords());
        return Result.succ(retMap);
    }
}
